#include <stdio.h>
#include "arr.h"
#include "hlog.h"
#include <sys/time.h>
#include <signal.h>
#include <hv/hloop.h>

void mylogger(int loglevel, const char* buf, int len) {
    if (loglevel >= LOG_LEVEL_ERROR) {
        stderr_logger(loglevel, buf, len);
    }

    if (loglevel >= LOG_LEVEL_INFO) {
        file_logger(loglevel, buf, len);
    }

    // network_logger(loglevel, buf, len);
}
void mylog(htimer_t *t)
{

    static int cnt = 0;
    hlogd("[%d] Do you recv me?", ++cnt);
    hlogi("[%d] Do you recv me?", ++cnt);
    hloge("[%d] Do you recv me?", ++cnt);
}

ARRAY_DECL(int, myints); 
int main(int argc, char const* argv[])
{
  // 设置log文件
  // 用hloop也能简单的实现一个定时器事件
  logger_set_handler(hlog, mylogger);
  hlog_set_file("loop.log");
  logger_enable_color(hlog, 1);
  hloop_t *loop= hloop_new(0);
  htimer_add(loop, mylog, 1000, INFINITE);
  hloop_run(loop);
  hloop_free(&loop);
  return 0;


  struct itimerval ti;
  ti.it_interval.tv_sec = 2;
  ti.it_interval.tv_usec = 0;
  ti.it_value.tv_sec = 2;
  ti.it_value.tv_usec = 0;
  
  setitimer(ITIMER_REAL, &ti, NULL);
  struct sigaction act;
  act.sa_flags = 0;
  sigaddset(&act.sa_mask, SIGALRM);
  act.sa_handler = mylog;
  sigaction(SIGALRM, &act, NULL);
  

  struct myints test;
  myints_init(&test, 100);
  int i = myints_maxsize(&test);
  while(1) {
  // printf("%d\n", i);
  }

  return 0;
}
